<?php
 require_once '../php_includes.php';
	//require_once 'admin_options.php';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- The first form displays all the managers whose does not have employees working.
     Query select the manager id, first and last name and count the number of times each ManagerID is appears/assigned to an Employee
.
     If count is equal to 1, then Manager has no employee. 

     The second form tranfer employee from manager to another
     The 1st manager will have their employees transfer to another manager.
     The 2nd manager that will have employees transfer from another manager.
-->

<html xmlns="http://www.w3.org/1999/xhtml">

  <head>
    <title>Payroll and Timesheet Management Website</title>
    <link rel="stylesheet" type="text/css" href="../styles.css"/>
	</script>
  </head>
  <body>
  
	<?php
	//show the logo
	echo "<div class=\"logo\">\n";
	echo "	<img src=\"";
	echo "../" . $header_image;
	echo "\" alt=\"";
	echo $header_image_alt;
	echo "\" />\n";
	echo "</div>\n";
	?>
        <div class="user_links">
		<a href="adminlogs.php">Logs</a> &nbsp;&nbsp;|&nbsp;&nbsp;
		<a href="adminMessage.php">Set Admin Message</a> &nbsp;&nbsp;|&nbsp;&nbsp;
		<a href="addmanager.php">Add Manager</a> &nbsp;&nbsp;|&nbsp;&nbsp;
		<a href="adminDeletion.php">Delete Manager and Transfer Employees</a> &nbsp;&nbsp;|&nbsp;&nbsp;
		<a href="adminManager.php">Change Employee's Manager</a> &nbsp;&nbsp;|&nbsp;&nbsp;
	</div>
        <p></p>
        <div class="center">
		<p>
        <span class="pageheader"> Admin Delete Manager </span>
        </p>
        </div>
        <p> <br /> </p>
        <form action = "adminMgrDel.php" method = "post">
         <div class="center">
         <select name = "Managers">
        <?php 
           sqlConnect();
           
           $managers = 'select ManagerID,EmployeeFName,EmployeeLName, COUNT(ManagerID) FROM Employee GROUP BY ManagerID';
           $theResult = sqlQuery($managers);
           $theRow = mysql_fetch_row($theResult);
     
        do{
            if($theRow[3] == 1)
            {
              echo "<option value = '$theRow[0]'> $theRow[0]  $theRow[1]  $theRow[2] </option>";
            }
            $theRow = mysql_fetch_row($theResult);
          }while($theRow);
          sqlExit();
        ?>
        </select>
        <p>
             <input type ="hidden" name = "hide" value = "hidden"/>
             <input type ="submit" value = "Delete Manager" class="button"/>
        </p>
         </div>
        </form>
        <p> <br /> </p>
        <div class="center">
		<p>
        <span class="pageheader"> Admin Transfer Employees </span>
        </p>
        </div>
        <form action = "adminTransfer.php" method = "post">
       <div class="center">
        <p> <br /> </p>
        <pre> FROM       :     To     </pre>
        <select name = "firstManager">
        <?php 
           sqlConnect();

           $managers = 'select EmployeeID, EmployeeFName, EmployeeLName FROM Employee WHERE EmployeeID IN (select distinct(ManagerID) from Employee)';
           $theResult = sqlQuery($managers);
           $theRow = mysql_fetch_row($theResult);
     
        do{
            echo "<option value = '$theRow[0]'> $theRow[0]  $theRow[1]  $theRow[2] </option>";
            $theRow = mysql_fetch_row($theResult);
          }while($theRow);
        ?>
        </select>
        <select name = "SecondManager">
        <?php 
           sqlConnect();
           $managers = 'select EmployeeID, EmployeeFName, EmployeeLName FROM Employee WHERE EmployeeID IN (select distinct(ManagerID) from Employee)';
           $theResult = sqlQuery($managers);
           $theRow = mysql_fetch_row($theResult);
     
        do{
            echo "<option value = '$theRow[0]'> $theRow[0]  $theRow[1]  $theRow[2] </option>";
            $theRow = mysql_fetch_row($theResult);
          }while($theRow);
          sqlExit();
        ?>
        </select>
        <p>
             <input type ="hidden" name = "hide" value = "hidden"/>
             <input type ="submit" value = "Transfer Employees" class="button"/>
        </p>
         </div>
        </form>

</body>
</html>
	